//
//  SHD_TagViewController.m
//  B段项目
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 谢美娜. All rights reserved.
//

#import "SHD_TagViewController.h"

@interface SHD_TagViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@end

@implementation SHD_TagViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"标签";
    
    
}
-(void)loadView
{
    [super loadView];
    _dataArray = [NSMutableArray array];
    _dataTagArray = [NSMutableArray array];
    UICollectionViewFlowLayout *tagFlowLayout = [[UICollectionViewFlowLayout alloc]init];
    tagFlowLayout.minimumInteritemSpacing = 2.5 * FitHeight;
    tagFlowLayout.minimumLineSpacing = 2.5 * FitWidth;
    tagFlowLayout.itemSize = CGSizeMake(120 * FitWidth, 120 * FitHeight);
    _tagCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 375 * FitWidth, (667 - 64) * FitHeight) collectionViewLayout:tagFlowLayout];
    [_tagCollectionView registerClass:[SHD_TagCollectionCell class] forCellWithReuseIdentifier:@"identifier"];
    _tagCollectionView.delegate = self;
    _tagCollectionView.dataSource = self;
    [_tagCollectionView NightWithType:UIViewColorType2];
    _tagCollectionView.contentInset = UIEdgeInsetsMake(5 * FitHeight, 5 * FitWidth, 0, 5 * FitWidth);
    [_tagCollectionView NightWithType:UIViewColorType2];
    [self.view addSubview:_tagCollectionView];
    [self getData];
}
-(NSInteger )collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SHD_TagCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"identifier" forIndexPath:indexPath];
    cell.tagList = _dataArray[indexPath.row];
    cell.nav = self.navigationController;
    return cell;
}
-(void)getData
{
    [HTTPMethod getDataByString:@"http://api2.pianke.me/timeline/tags" BODYDic:[ChangeString changeStringToDictionary:@"auth=&client=1&deviceid=5AA12B08-7AD2-4ED0-B4EB-571025443952&limit=10&start=0&version=3.0.6"] WithDataBlock:^(id data) {
        NSArray *dataArray = [[data objectForKey:@"data"] objectForKey:@"list"];
        for (NSDictionary *dic in dataArray) {
            SHD_TagList *list = [[SHD_TagList alloc]init];
            [list setValuesForKeysWithDictionary:dic];
            [_dataArray addObject:list];
            [_dataTagArray addObject:list];
        }
        
        [_tagCollectionView reloadData];
        
    }];
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    SHD_DataTageViewController *sdv = [[SHD_DataTageViewController alloc]init];
    [self.navigationController pushViewController:sdv animated:YES];
    sdv.tag = [_dataArray[indexPath.row] Tag];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
